//
//  ReportListOneController.m
//  FinancialProduct
//
//  Created by Stella on 2017/9/20.
//  Copyright © 2017年 maq. All rights reserved.
//
#import "UserModel.h"
#import "HandleNetProduct.h"
#import "TransactionInfoCell.h"
#import "ReportController.h"
#import "CKPuslichTool.h"

#import "SearchController.h"
#import "ReportListOneController.h"

@interface ReportListOneController (){
    NSString *searchName;
    BOOL isReport;
}
@property (weak, nonatomic) IBOutlet UIView *noDataView;
@property (weak, nonatomic) IBOutlet UITableView *myTable;
@property (weak, nonatomic) IBOutlet UIButton *searchBt;
@property(strong, nonatomic)NSArray *dataArray;
@end

@implementation ReportListOneController

- (void)viewDidLoad {
    [super viewDidLoad];
    searchName=@"";
    self.myTable.estimatedRowHeight=50;
    self.myTable.rowHeight = UITableViewAutomaticDimension;
    [self.searchBt setTitle:@"搜索产品" forState:UIControlStateNormal];
    [self.searchBt setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    if ([self.title isEqualToString:@"产品报告"]) {
        isReport=YES;
    }else{
        isReport=NO;
    }
    [self getListData];
}
-(IBAction)rightButton:(UIButton *)barBt{
    [self.searchBt setTitle:@"搜索产品" forState:UIControlStateNormal];
    [self.searchBt setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    //去搜索页面
    SearchController *vc=(SearchController *)[CKPuslichTool getViewControllerFromStroyBoard:@"My" viewID:@"SearchController"];
    vc.whereFrom=@"Report";
    vc.returnSearchContent = ^(NSString *searchContent) {
        searchName=searchContent;
        [self.searchBt setTitle:searchName forState:UIControlStateNormal];
        [self.searchBt setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        [self getListData];
    };
    
    [self.navigationController pushViewController:vc animated:YES];
    
}
-(void)getListData{
    UserModel *model=[UserModel getUser];
    int mid=[model.CustomerID intValue];
    NSDictionary *params;
    if (isReport) {
        params=@{@"AAAMethodName":@"InfodisclosureReport",
                 @"CustomerID":@(mid),@"ProductName":searchName};
    }else{
        params=@{@"AAAMethodName":@"InfodisclosureNotice",@"CustomerID":@(mid),
              @"ProductName":searchName};
    }
    
    [HandleNetProduct getListforParams:params Success:^(NSArray *data) {
        
        if (data.count>0) {
            
            _dataArray=data;
            self.noDataView.hidden=YES;
        }else{
            self.noDataView.hidden=NO;
        }
        [self.myTable reloadData];
    } Failure:^(NSString *errorInfo) {
        
    }];
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - Table view data source
//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    return 50;
//
//}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    return 1;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return self.dataArray.count;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    TransactionInfoCell *cell=[tableView dequeueReusableCellWithIdentifier:@"TransactionInfoCell" forIndexPath:indexPath];
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    cell.accessoryType=UITableViewCellAccessoryNone;
    
    cell.nameLa.text=_dataArray[indexPath.row][@"ProductName"];
    
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0.01f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0.01;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    ReportController *vc=(ReportController *)[CKPuslichTool getViewControllerFromStroyBoard:@"My" viewID:@"ReportController"];
    if (isReport) {
        vc.title=@"产品报告";
    }else{
        vc.title=@"产品公告";
    }
    
    vc.ProductId=self.dataArray[indexPath.row][@"ProductId"];
    [self.navigationController pushViewController:vc animated:YES];
}


@end
